<script type="text/javascript">
var paginationTotal = 1;//记录总数
$(document).ready(function(){
	initData(0);
	$('#dateFrom,#dateTo').datepicker({
		changeMonth: true,
		changeYear: true,			 
		dateFormat: 'yy-mm-dd'
	});
	
	$("#tipDialog").dialog({
		autoOpen:false,
		modal:true,
		show:"slide",
		buttons:{
				"OK":function(){
					$(this).dialog("close");					
					initData(0);
				}
		}
	});
	
});

function loadData(page,pageSize){
	
    $.ajax({
        type: "POST",
        async: false,
        dataType: "json",
        url: "/merchant/alert/alert-messages",
        data:{},
        success: function(json) {
        	var html ='';
        	if(json.ask==1){           
            	if (typeof json.result == 'undefined') return;
            	$.each(json.result,function(k,v){
            		
                	html +='<div class="row height25">';
                	
                	html +='<div class="cell" style="width:58%;text-align:left;">';
                	html +='<span style="cursor:pointer;margin-left:8px;">'+v.am_title+'</span></div>';
                	
                	html +='<div class="cell" style="width:20%;">';
                	html +='<div style="float:left;margin-left:35px;cursor:pointer;" onclick="selectLevel(this,'+v.am_config_id+')" title="点击修改">';
                	html += v.send_level+'</div></div>';
                	
                	html +='<div class="cell" style="width:11%;">';
                	if(v.am_is_email==1){
                		html += '<input type="checkbox" name="am_is_email" value="'+v.am_id+'" checked="checked" onclick="isEmail(this,'+v.am_config_id+')" />';
                	}else{
                		html += '<input type="checkbox" name="am_is_email" value="'+v.am_id+'" onclick="isEmail(this,'+v.am_config_id+')" />';
                	}
                	html +='</div>';
                	
                	html +='<div class="cell2" style="width:11%;">';
                	if(v.am_is_alert==1){
                		html += '<input type="checkbox" name="am_is_alert" value="'+v.am_id+'" checked="checked" onclick="isAlert(this,'+v.am_config_id+')" />';
                	}else{
                		html += '<input type="checkbox" name="am_is_alert" value="'+v.am_id+'" onclick="isAlert(this,'+v.am_config_id+')" />';
                	}
                	html +='</div>';
                						
                	html +='</div>';
            	});
            	
         	}else{
         		paginationTotal = json.total;
         		html +='<div class="row height25" style="text-align:center;">No Data.</div>';
         	}
         	$("#tab-div").html(html);
    
      	}
    });
}

function selectLevel(obj,config_id){
	var text = $.trim($(obj).text());
	var html = '';
	var selected = '';
	var selected0 ='',selected1 ='',selected2 ='';
	if(text=='Notice'){
		selected0 = 'selected';
	}
	if(text=='Warning'){
		selected1 = 'selected';
	}
	if(text=='Important'){
		selected2 = 'selected';
	}
	html += '<select name="send_level" onchange="setLevel(this,'+config_id+')">';
	html += '<option value="0" '+selected0+'>Notice</option>';
	html += '<option value="1" '+selected1+'>Warning</option>';
	html += '<option value="2" '+selected2+'>Important</option>';
	html += '</select>';
	$(obj).parent().html(html);
}

function setLevel(obj,config_id){
	var send_level = $(obj).val();
//	alert(send_level);
	$.ajax({
        type: "POST",
        async: false,
        dataType: "json",
        url: "/merchant/alert/set-level",
        data:{'am_level':send_level,'am_config_id':config_id},
        success: function(json) {
        	var html ='';
        	if(json.ask==1){
            	html +='set up successfully';
            	
         	}else{         		
         		html +='set up failed';
         	}
         	$("#tipDialog").html(html).dialog("open");    
    
      	}
    });
	
}

function isEmail(obj,config_id){
	var am_is_email = $(obj).val();
	$.ajax({
        type: "POST",
        async: false,
        dataType: "json",
        url: "/merchant/alert/send-setting",
        data:{
            'am_is_email':am_is_email,'am_config_id':config_id
         },
        success: function(json) {
        	var html ='';
        	if(json.ask==1){
            	html +='set up successfully';
            	
         	}else{         		
         		html +='set up failed';
         	}
         	$("#tipDialog").html(html).dialog("open");    
    
      	}
    });
}

function isAlert(obj,config_id){
	var am_is_alert = $(obj).val();
	$.ajax({
        type: "POST",
        async: false,
        dataType: "json",
        url: "/merchant/alert/send-setting",
        data:{
            'am_is_alert':am_is_alert,'am_config_id':config_id
         },
        success: function(json) {
        	var html ='';
        	if(json.ask==1){
            	html +='set up successfully';
            	
         	}else{         		
         		html +='set up failed';
         	}
         	$("#tipDialog").html(html).dialog("open");    
    
      	}
    });
}

</script>
<style>
	
	.bgc{background:#F2F8FD}
	.radiu{-webkit-border-radius: 10px;-moz-border-radius:10px;border-radius:10px;overflow: hidden;}
	.info-top{height:10px}
	.tab-li{ float:left; padding:0; cursor:pointer; background:url(/images/menu-li-bg.gif) no-repeat center top; width:92px; height:25px; line-height:25px; text-align:center; color:white}
	.tab-li-click{background:url(/images/menu-li-bg-hover.gif) no-repeat center top}
	.tab-li:hover{ background:url(/images/menu-li-bg-hover.gif) no-repeat center top}
	.info-header{width:100%;height:200px;background:url(/images/nav-bg.png) no-repeat center top;border-bottom:1px solid #CCC;position:relative}
	.info-header h3{text-indent:10px;}
	.info-content{}
	.info-content-body{border-top:1px solid #CCC;width:100%;clear:both;min-height: 200px;}
	.info-content-menu{border-top:1px solid #CCC;width:100%;height:25px}
	.info-header-content{position:absolute;top:50px;left:10px;width:870px;border:1px solid #CCC;}
	.cell20{width:180px;height:25px;line-height:25px;display:inline-block;overflow:hidden;border-bottom:1px solid #CCC;margin:0px;border-right:1px solid #CCC;margin:0px;float:left}
	.cell30{width:253px;height:25px;line-height:25px;display:inline-block;overflow:hidden;border-bottom:1px solid #CCC;margin:0px;border-right:1px solid #CCC;margin:0px;margin:0px;float:left}
	.no-bottom{border-bottom:none}
	.no-right{border-right:none}
	.error{color:red}
		
.line1 {
	height: 25px;
	width: 100%;
	background: none repeat scroll 0 0 #FFFFFF;
	text-align:center;
}
.line1:hover, .line2:hover{
	background-color:#F2F8F9;
}

.line2 {
	height: 25px;
	width: 100%;
}

.cell2 {
    background: url("") repeat-y scroll right top transparent;
    float: left;
    height: 25px;
    line-height: 25px;
    overflow: hidden;
    text-align: center;
}

</style>
<div class="position"><a href='/default/index'><{$languages['HOME']}></a> &gt; <a href='/merchant/my-account'><{$languages['MERCHANT_CENTER']}></a>  &gt; <{$languages['OPERATION']}> &gt; <{$languages['MESSAGE_LIST']}></div>

<div style="color:red; margin-top:10px;" id="message"></div>

<div class="row height25 row-header">
	<div class="cell sort" style="width:58%">标题</div>
	<div class="cell" style="width:20%">级别</div>
	<div class="cell" style="width:11%">发送警报</div>
	<div class="cell2" style="width:11%">发送邮箱</div>
</div>

<div class="tab-div" id="tab-div">	</div>

<div id="right_confirm" style="display: none;">
	<p style="text-align:center;font-size: 14px;color: red;font-weight: bold;">
	Are you sure to delete it?
	</p>
</div>

<div id="tipDialog" style="display:none" title="Tip"></div>